#!/bin/sh

# benchmark performance 

# instructions
# run as root!
# get apache pid (service apache status), and set below
apache_pid=21531

# load test 1x, 10x, 100x
ab -n 1000 -c 1 -g load1x.dat http://localhost/app
ab -n 1000 -c 10 -g load10x.dat http://localhost/app
ab -n 1000 -c 100 -g load100x.dat http://localhost/app

# call to gnuplot to plot it
gnuplot loadTest.plt

# set up cgroups
cgcreate -g cpu,memory:apache
cgclassify --sticky -g memory:apache $apache_pid
cgclassify --sticky -g cpu:apache $apache_pid

# memory performance  (10MB, 100MB, 1000MB)
echo 10M > /sys/fs/cgroup/memory/apache/memory.limit_in_bytes
service apache2 restart
ab -n 100 -c 10 -g performance_memory_10MB.dat http://localhost/app
echo 100M > /sys/fs/cgroup/memory/apache/memory.limit_in_bytes
service apache2 restart
ab -n 100 -c 10 -g performance_memory_100MB.dat http://localhost/app
echo 1000M > /sys/fs/cgroup/memory/apache/memory.limit_in_bytes
service apache2 restart
ab -n 100 -c 10 -g performance_memory_1000MB.dat http://localhost/app

gnuplot memoryTest.plt

#reset memory for next test
echo -1 > /sys/fs/cgroup/memory/apache/memory.limit_in_bytes

# cpu performance 
echo 10 > /sys/fs/cgroup/cpu/apache/cpu.shares 
service apache2 restart
ab -n 100 -c 10 -g performance_cpu_1perc.dat http://localhost/app
echo 102 > /sys/fs/cgroup/cpu/apache/cpu.shares 
service apache2 restart
ab -n 100 -c 10 -g performance_cpu_10perc.dat http://localhost/app
echo 1024 > /sys/fs/cgroup/cpu/apache/cpu.shares 
service apache2 restart
ab -n 100 -c 10 -g performance_cpu_100perc.dat http://localhost/app

gnuplot cpuTest.plt

#reset cpu shares
echo -1 > /sys/fs/cgroup/cpu/apache/cpu.shares 






